namespace devtm.Aop.Emit
{
    using System;


    [Serializable]
    public class EmitArrayIndexerExpression : EmitExpression
    {
        private EmitExpressionCollection indices;


        public EmitArrayIndexerExpression()
        {
        }

        public EmitArrayIndexerExpression(EmitExpression targetObject, params EmitExpression[] indices)
        {
            this.TargetObject = targetObject;
            this.indices = new EmitExpressionCollection();
            this.indices.AddRange(indices);
        }

        public EmitExpressionCollection Indices
        {
            get
            {
                if (this.indices == null)
                {
                    this.indices = new EmitExpressionCollection();
                }
                return this.indices;
            }
        }

        public EmitExpression TargetObject { get; set; }

        public override void Compile(CilWorker gen)
        {

            TargetObject.UserData.Add("way", "get");
            TargetObject.Compile(gen);
            TargetObject.UserData.Remove("way");

            foreach (EmitExpression item in indices)
            {
                item.Compile(gen);
            }

        }

    }

}
